const express = require('express');
const router = express.Router();
const reservationController = require('../controllers/reservationController');
const { authenticateToken, authenticateAdmin } = require('../middleware/auth');
const { adminLogger } = require('../middleware/adminLogger');

// ===== 用户端接口 =====
router.post(
  '/',
  authenticateToken,
  reservationController.createReservation
);

router.get(
  '/my-reservations',
  authenticateToken,
  reservationController.getReservations
);

router.post(
  '/:reservationId/cancel',
  authenticateToken,
  reservationController.cancelReservation
);

// ===== 管理员端接口 =====
router.get(
  '/admin/available-books',
  authenticateAdmin,
  reservationController.getAvailableBooks
);

// 获取所有预约（管理员）
router.get(
  '/admin/all',
  authenticateAdmin,
  reservationController.getAllReservations
);

// 通知预约用户（管理员）
router.post(
  '/admin/:reservationId/notify',
  authenticateAdmin,
  adminLogger('notify_reservation', (req) => `通知预约用户，预约ID: ${req.params.reservationId}`),
  reservationController.notifyReservation
);

// 获取预约统计（管理员）
router.get(
  '/admin/stats',
  authenticateAdmin,
  reservationController.getReservationStats
);

module.exports = router;

